<template>
	<view class="container" :style="{minHeight:$height()}">
		<view class="banner">
			<image :src="$utils.imagePath(`/upload/image/banner.png`)" mode="widthFix"></image>
		</view>
		<view class="custom-count">
			<text class="title">
				任务
			</text>
			<view class="items king-flex king-flex__between">
				<view class="item king-flex king-flex__column">
					<text class="tip">累计客户（家）</text>
					<text class="num">{{custonCount}}</text>
				</view>
				<view class="item1 king-flex king-flex__column">
					<text class="tip">累计收入（{{getMoney(1,userinfo.money||'0.00')}}）</text>
					<text class="num">{{getMoney(2,userinfo.money||'0.00')}}</text>
				</view>
			</view>
		</view>

		<view class="flw">
			<text class="title">学习售电</text>
			<view class="flw-box king-flex king-flex__between">
				<view class="flw-item" @click="$next(`/pages/functionCore/customer/list`,true)">
					<image src="@/static/img/flw1.png" mode="widthFix"></image>
				</view>
				<view class="flw-item" @click="$next(`/pages/functionCore/groundPush/groundPushCustomer`,true)">
					<image src="@/static/img/flw2.png" mode="widthFix"></image>
				</view>
				<view class="flw-item" @click="$next(`/pages/functionCore/customCompanyIndex`,true)">
					<image src="@/static/img/flw3.png" mode="widthFix"></image>
				</view>
				<view class="flw-item" @click="$next(`/pages/functionCore/counter`,true)">
					<image src="@/static/img/flw4.png" mode="widthFix"></image>
				</view>
				<view class="flw-item" @click="$next(`/pages/contract/list`,true)">
					<image src="@/static/img/flw5.png" mode="widthFix"></image>
				</view>
				<view class="flw-item" @click="$next(`/pages/functionCore/groundPush/intendedCustomer`,true)">
					<image src="@/static/img/flw6.png" mode="widthFix"></image>
				</view>
				<view class="flw-item" @click="getMap(`/pages/functionCore/CustomerPoolMap/CustomerPoolMap`)">
					<image src="@/static/img/flw7.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
		<status-modal :showSign="showSign" :showSignContract="showSignContract" :tenantCode="tenantCode"
			:showStatus="showStatus" :userType="userType" :updateDate="userinfo.updateDate"></status-modal>
		<login-modal />

	</view>
</template>

<script>
	import statusModal from '@/components/statusModal/statusModal.vue'
	export default {
		data() {
			return {
				showSign: false,
				showSignContract: false,
				showStatus: false,
				userType: 0,
				userinfo: {},
				custonCount: 0,
				areaStrArr: "",
				tenantCode: uni.getStorageSync("tenantCode")
			}
		},
		components: {
			statusModal
		},
		onShow() {

			this.getUser()
			this.getSignedTowner()

		},
		onLoad() {
			this.getMyCustom()
		},
		methods: {
			getMoney(type, money) {
				if (type == 1) {
					if (parseFloat(money) < parseFloat("10000")) {
						return "元"
					} else {
						return "万元"
					}
				}

				if (type == 2) {
					if (parseFloat(money) < parseFloat("10000")) {
						return money
					} else {
						return (parseFloat(money) / parseFloat("10000")).toFixed(2)
					}
				}
			},
			getMyCustom() {
				this.$axios.request(this.$api.getCustomRes, "GET", {
					limit: 1,
					page: 1,
					type: 0,
					orderField: 'id',
					order: 'desc'
				}).then((val) => {
					this.custonCount = val.data.total
				})
			},
			getSignedTowner() {
				this.$axios.request(this.$api.getSignedAreaRes, "GET").then((val) => {
					this.areaStrArr = val.data || '暂无区域'
				})
			},
			// 去往客户池地图
			getMap(path) {
				uni.getLocation({
					type: 'gcj02',
					success: (res) => {
						if (res.latitude) {
							this.$next(
								`${path}?userid=${this.userinfo.id}&latitude=${res.latitude}&longitude=${res.longitude}`,
								true)
						}
					},
					fail: (res) => {
						// this.$next(`${path}?userid=${this.userinfo.id}&latitude=31.292634&longitude=120.673828`,true)
						this.$next(
							`${path}?userid=${this.userinfo.id}&latitude=31.3374923393393&longitude=120.97601494772528`,
							true)
					}
				})
			},
			getUser() {
				this.$axios.request(this.$api.getUser, "GET").then((val) => {
					this.userinfo = val.data
					uni.setStorageSync("userInfo_level",this.userinfo.level)
					this.userType = val.data.userType
					if (val.data.realname == '') {
						this.showSign = true
						this.showStatus = false
						this.showSignContract = false
					} else if (val.data.status == 0) {
						this.showStatus = true
						this.showSign = false
						this.showSignContract = false
					} else if (val.data.status == 1 && val.data.sign == 0) {
						this.showSignContract = true
						this.showSign = false
						this.showStatus = false
					} else {
						this.showSign = false
						this.showStatus = false
						this.showSignContract = false
					}
					this.mobile = val.data.mobile.substr(0, 3) + "****" + val.data.mobile.substr(7)
				}).catch((e) => {
					console.log(e)
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	.container {
		background: #ECEEEE;
	}

	.banner {
		image {
			width: 100%;
		}
	}

	.flw {
		background: #FFFFFF;
		padding: 47rpx;
		margin-top: 20rpx;

		.flw-box {
			margin-top: 20rpx;
			flex-wrap: wrap;
		}

		.flw-item {
			width: 322rpx;
			margin-top: 10rpx;

			image {
				width: 100%;
			}
		}
	}

	.custom-count {
		background: #FFFFFF;
		padding: 47rpx;

		.items {
			margin-top: 20rpx;

			.item {
				width: 320rpx;
				height: 156rpx;
				background-image: url(@/static/img/task1.png);
				background-repeat: no-repeat;
				background-size: 100%;


			}

			.item1 {
				width: 320rpx;
				height: 156rpx;
				background-image: url(@/static/img/task2.png);
				background-repeat: no-repeat;
				background-size: 100%;

			}

			.tip {
				color: #022551;
				font-size: 26rpx;
				font-weight: 600;
				margin-top: 33rpx;
				margin-left: 40rpx;
			}

			.num {
				color: #022551;
				font-size: 60rpx;
				font-weight: bold;
				margin-left: 40rpx;
			}
		}
	}
</style>